package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ImageUtil;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.PersonCenterActivity;

import java.io.File;


public class PersonCenterActivityPresenter extends BasePresenter<PersonCenterActivity> {
    /**
     * 上传图片
     *
     * @param file 文件
     * @return
     */
    public void uploadImg(File file) {
        httpService.uploadImg(file)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<String>> response) {
                        HttpData<String> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            settingTx(SPUtil.get(SPConfig.ID, ""), httpData.getData());
                        }
                    }
                });
    }

    public void settingTx(String id, String txUrl) {
        httpService.setMineTxName(id, txUrl)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData<String> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updatePath(txUrl);
                        }
                    }
                });
    }


}


